//
//  CZHomeViewController.m
//  OCKSFWeibo
//
//  Created by 盛 发 况 on 16/4/18.
//  Copyright © 2016年 盛 发 况. All rights reserved.
//

#import "CZHomeViewController.h"
#import "CZOneViewController.h"
#import "UIBarButtonItem+Item.h"
#import "CZTitleButton.h"
#import "CZPopMenu.h"
#import "CZCover.h"

@interface CZHomeViewController ()<CZCoverDelegate>
@property (nonatomic, strong) CZOneViewController *one;
@property (nonatomic, weak) CZTitleButton *titleButton;

@end

@implementation CZHomeViewController

- (CZOneViewController *)one {
    if (_one == nil) {
        
        _one = [[CZOneViewController alloc] init];
    }
    return _one;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // 设置导航条内容
    [self setUpNavgationBar];
}

#pragma mark --设置导航条内容
- (void)setUpNavgationBar {
    //左边
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"navigationbar_friendsearch"] highImage:[UIImage imageNamed:@"navigationbar_friendsearch_highlighted"] target:self action:@selector(friendsearch) forControlEvents:UIControlEventTouchUpInside];
    
    //右边
    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"navigationbar_pop"] highImage:[UIImage imageNamed:@"navigationbar_pop_highlighted"] target:self action:@selector(pop) forControlEvents:UIControlEventTouchUpInside];
    
    //中间标题+图片按钮
    CZTitleButton *titleButton = [CZTitleButton buttonWithType:UIButtonTypeCustom];
    _titleButton = titleButton;
    
    [titleButton setTitle:@"首页" forState:UIControlStateNormal];
    [titleButton setImage:[UIImage imageNamed:@"navigationbar_arrow_up"] forState:UIControlStateNormal];
    [titleButton setImage:[UIImage imageNamed:@"navigationbar_arrow_down"] forState:UIControlStateSelected];
    // 高亮的时候不需要调整图片
    titleButton.adjustsImageWhenHighlighted = NO;
    
    [titleButton addTarget:self action:@selector(titleClick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.navigationItem.titleView = titleButton;
}

//点击事件的实现
- (void)friendsearch {

    NSLog(@"点击了首页控制器的左边按钮...");
}
- (void)pop {

    NSLog(@"点击了右边按钮...");
    //[self.titleButton setImage:nil forState:UIControlStateNormal];
}
// 点击标题按钮
- (void)titleClick:(UIButton *)button {

    button.selected = !button.selected;

    // 弹出蒙板
    CZCover *cover = [CZCover show];
    cover.delegate = self;

    // 弹出pop菜单
    CGFloat menuX = (self.view.width - 200) * 0.5;
    CGFloat menuY = 55;
    CGFloat menuW = 200;
    CGFloat menuH = menuW;
    
    CZPopMenu *menu = [CZPopMenu showInRect:CGRectMake(menuX, menuY, menuW, menuH)];
    menu.contentView = self.one.view;
}

//实现CZCoverDelegate 点击蒙板的时候调用
- (void)coverDidClickCover:(CZCover *)cover {

    // 隐藏pop菜单
    [CZPopMenu hide];
    
    self.titleButton.selected = NO;

}



@end






